import { WebSiteWithCategory } from '@/types/website';
import { ProcessType } from './Step';
import { Logic } from './Match/Pick';
import type { Response } from '@/utils/request';

export type StartData = {
  mapping_categories: WebSiteWithCategory[];
};

export type Option = {
  option_name: string;
  option_value: string;
  option_code: string;
  image_url?: string;
};
export type WebOption = Option & {
  website_code: string;
  category_name: string;
  condition_name: string;
};

type BaseMatch = {
  website_code: string;
  category_name: string;
  category_path: string;
  condition_name: string;
  condition_code: string;
  category_code: string;
};

export type Match = BaseMatch & { options: Option[] };
export type WebMatch = BaseMatch & { options: WebOption[] };

export type Condition = {
  condition_name: string;
  category_image_url?: string;
  matches: Match[];
  isEdit?: boolean;
  alias_name?: string;
  match_rule?: Logic<{ condition_id: string }>;
  isConfig?: boolean;
};

export type MatchData = {
  conditions: Condition[];
};

export type ConditionOption = {
  option_name: string;
  image_url?: string;
  matches: WebMatch[];
  alias_name: string;
  isEdit?: boolean;
};

export type OptionCondition = {
  condition_name: string;
  alias_name?: string;
  options: ConditionOption[];
};

export type OptionData = {
  conditions: OptionCondition[];
};

export type TableRow = Omit<Condition, 'matches'> & {
  isEdit?: boolean;
  rowSpan?: number;
  website: Match;
  alias_name: string;
};

export type SpecOption = {
  spec_option_img_url: string;
  spec_option_value: string;
  spec_option_name: string;
};

export type Spec = {
  spec_code?: string;
  spec_name: string;
  spec_options: SpecOption[];
};

export type Result = {
  condition_name: string;
  children: {
    option_name: string;
  }[];
};

export type ResultData = {
  conditions: string[];
  options: Record<string, string[]>;
};

export type SqlData = {
  genExcel: string;
  uploadExcel?: string;
};

export type FetchProcess = (processName: ProcessType) => Promise<void>;
export type UpdateProcess = (confirmed?: boolean) => Promise<Response>;
export type JumpType = {
  process_name: ProcessType;
  callback?: (...args) => Promise<any>;
  redirect?: boolean;
  isNext?: boolean;
};
